<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Hotels
 * This class represents a data access object for the database table 'hotels'.
 */
class Hotels {


	public $dao = null;

	private $i = 1;

	/**
	 * associated database field: hotelId, type: int, is nullable: false
	 */
	private $hotelId  = 0;

	/**
	 * associated database field: hotelName, type: varchar, is nullable: true, character set: utf8, max length: 45
	 */
	private $hotelName;

	/**
	 * associated database field: hotelURL, type: varchar, is nullable: true, character set: utf8, max length: 100
	 */
	private $hotelURL;

	/**
	 * associated database field: addressId, type: int, is nullable: false
	 */
	private $addressId;

	/**
	 * associated database field: countryCode, type: varchar, is nullable: false, character set: utf8, max length: 20
	 */
	private $countryCode;

	/**
	 * associated database field: starRatingId, type: int, is nullable: false
	 */
	private $starRatingId;

	private $hotelcharacteristicsArray = null;

	private $roomsArray = null;

	private $roombookingsArray = null;

	private $address = null;

	private $country = null;

	private $starRatings = null;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("Hotels");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['hotelId'])) $this->hotelId = $row['hotelId'];
		if(isset($row['hotelName'])) $this->hotelName = $row['hotelName'];
		if(isset($row['hotelURL'])) $this->hotelURL = $row['hotelURL'];
		if(isset($row['addressId'])) $this->addressId = $row['addressId'];
		if(isset($row['countryCode'])) $this->countryCode = $row['countryCode'];
		if(isset($row['starRatingId'])) $this->starRatingId = $row['starRatingId'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Hotels
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'hotelId: '.(($escapeQuotationMarks===true) ? addslashes($this->hotelId) : $this->hotelId).', ';
		$s .= 'hotelName: '.(($escapeQuotationMarks===true) ? addslashes($this->hotelName) : $this->hotelName).', ';
		$s .= 'hotelURL: '.(($escapeQuotationMarks===true) ? addslashes($this->hotelURL) : $this->hotelURL).', ';
		$s .= 'addressId: '.(($escapeQuotationMarks===true) ? addslashes($this->addressId) : $this->addressId).', ';
		$s .= 'countryCode: '.(($escapeQuotationMarks===true) ? addslashes($this->countryCode) : $this->countryCode).', ';
		$s .= 'starRatingId: '.(($escapeQuotationMarks===true) ? addslashes($this->starRatingId) : $this->starRatingId);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Hotels
	 */
	public function toJSONString(){
		$fieldValues = array ("hotelId"=>$this->hotelId, "hotelName"=>$this->hotelName, "hotelURL"=>$this->hotelURL, "addressId"=>$this->addressId, "countryCode"=>$this->countryCode, "starRatingId"=>$this->starRatingId);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Hotels object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"hotels\">\n";
		$htmlCode .= '	<div class="hotels_hotelId">'.(($escapeHTML===true) ? htmlspecialchars($this->hotelId) : $this->hotelId)."</div>\n";
		$htmlCode .= '	<div class="hotels_hotelName">'.(($escapeHTML===true) ? htmlspecialchars($this->hotelName) : $this->hotelName)."</div>\n";
		$htmlCode .= '	<div class="hotels_hotelURL">'.(($escapeHTML===true) ? htmlspecialchars($this->hotelURL) : $this->hotelURL)."</div>\n";
		$htmlCode .= '	<div class="hotels_addressId">'.(($escapeHTML===true) ? htmlspecialchars($this->addressId) : $this->addressId)."</div>\n";
		$htmlCode .= '	<div class="hotels_countryCode">'.(($escapeHTML===true) ? htmlspecialchars($this->countryCode) : $this->countryCode)."</div>\n";
		$htmlCode .= '	<div class="hotels_starRatingId">'.(($escapeHTML===true) ? htmlspecialchars($this->starRatingId) : $this->starRatingId)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	/*
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}*/


	public static function loadAll(){
		$hotels = new Hotels();
		$rows = $hotels->dao->getData("");
		$hotelss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Hotels();
			$d->init($rows[$index]);
			array_push($hotelss,$d);
		}
		return $hotelss;
	}


	/**
	 * Load the Hotels uniquely by its primary key.
	 * @param hotelId the primary key
	 * @return Hotels Instance of {@link Hotels}
	 */
	public static function loadUnique($hotelId){
		$hotels = new Hotels();
		$rows = $hotels->dao->getData("`hotelId`='$hotelId'");
		$hotels->init($rows[0]);
		return $hotels;
	}


	/**
	 * Load all records of Hotels uniquely by its foreign keys:
	 * starRatingId
	 * @param starRatingId foreign key
	 * @return array of Instance of {@link Hotels}
	 */
	public static function loadByFKStarratingid($starRatingId){
		$hotels = new Hotels();
		$rows = $hotels->dao->getData("`starRatingId`='$starRatingId'");
		$hotelss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Hotels();
			$d->init($rows[$index]);
			array_push($hotelss,$d);
		}
		return $hotelss;
	}


	/**
	 * Load all records of Hotels uniquely by its foreign keys:
	 * addressId
	 * @param addressId foreign key
	 * @return array of Instance of {@link Hotels}
	 */
	public static function loadByFKAddressid($addressId){
		$hotels = new Hotels();
		$rows = $hotels->dao->getData("`addressId`='$addressId'");
		$hotelss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Hotels();
			$d->init($rows[$index]);
			array_push($hotelss,$d);
		}
		return $hotelss;
	}


	/**
	 * Load all records of Hotels uniquely by its foreign keys:
	 * countryCode
	 * @param countryCode foreign key
	 * @return array of Instance of {@link Hotels}
	 */
	public static function loadByFKCountrycode($countryCode){
		$hotels = new Hotels();
		$rows = $hotels->dao->getData("`countryCode`='$countryCode'");
		$hotelss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Hotels();
			$d->init($rows[$index]);
			array_push($hotelss,$d);
		}
		return $hotelss;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("hotelId"=>$this->hotelId, "hotelName"=>$this->hotelName, "hotelURL"=>$this->hotelURL, "addressId"=>$this->addressId, "countryCode"=>$this->countryCode, "starRatingId"=>$this->starRatingId);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("hotelId"=>$this->hotelId, "hotelName"=>$this->hotelName, "hotelURL"=>$this->hotelURL, "addressId"=>$this->addressId, "countryCode"=>$this->countryCode, "starRatingId"=>$this->starRatingId);
		$where = "`hotelId`='$hotelId'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['hotelId'])){
			$this->hotelId = $_POST['hotelId'];
		}
		if (isset($_POST['hotelName'])){
			$this->hotelName = $_POST['hotelName'];
		}
		if (isset($_POST['hotelURL'])){
			$this->hotelURL = $_POST['hotelURL'];
		}
		if (isset($_POST['addressId'])){
			$this->addressId = $_POST['addressId'];
		}
		if (isset($_POST['countryCode'])){
			$this->countryCode = $_POST['countryCode'];
		}
		if (isset($_POST['starRatingId'])){
			$this->starRatingId = $_POST['starRatingId'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['hotelId'])){
			$this->hotelId = $_GET['hotelId'];
		}
		if (isset($_GET['hotelName'])){
			$this->hotelName = $_GET['hotelName'];
		}
		if (isset($_GET['hotelURL'])){
			$this->hotelURL = $_GET['hotelURL'];
		}
		if (isset($_GET['addressId'])){
			$this->addressId = $_GET['addressId'];
		}
		if (isset($_GET['countryCode'])){
			$this->countryCode = $_GET['countryCode'];
		}
		if (isset($_GET['starRatingId'])){
			$this->starRatingId = $_GET['starRatingId'];
		}
	}


	/**
	 * Returns the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getHotelId(){
		return $this->hotelId;
	}


	/**
	 * Set the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @param hotelId String with the value for the field to be set
	 */
	public function setHotelId($hotelId){
		$this->hotelId = $hotelId;
	}


	/**
	 * Returns the value from the database field hotelName.
	 * In the database the field hotelName is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getHotelName(){
		return $this->hotelName;
	}


	/**
	 * Set the value from the database field hotelName.
	 * In the database the field hotelName is of type varchar.
	 * The database field is  nullable.
	 * @param hotelName String with the value for the field to be set
	 */
	public function setHotelName($hotelName){
		if(strlen($hotelName) > 45) throw new Exception("hotelName does not allow strings longer than 45 characters. The submitted string contains ".strlen($hotelName)." characters.");
		$this->hotelName = $hotelName;
	}


	/**
	 * Returns the value from the database field hotelURL.
	 * In the database the field hotelURL is of type varchar.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getHotelURL(){
		return $this->hotelURL;
	}


	/**
	 * Set the value from the database field hotelURL.
	 * In the database the field hotelURL is of type varchar.
	 * The database field is  nullable.
	 * @param hotelURL String with the value for the field to be set
	 */
	public function setHotelURL($hotelURL){
		if(strlen($hotelURL) > 100) throw new Exception("hotelURL does not allow strings longer than 100 characters. The submitted string contains ".strlen($hotelURL)." characters.");
		$this->hotelURL = $hotelURL;
	}


	/**
	 * Returns the value from the database field addressId.
	 * In the database the field addressId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getAddressId(){
		return $this->addressId;
	}


	/**
	 * Set the value from the database field addressId.
	 * In the database the field addressId is of type int.
	 * The database field is NOT nullable.
	 * @param addressId String with the value for the field to be set
	 */
	public function setAddressId($addressId){
		$this->addressId = $addressId;
	}


	/**
	 * Returns the value from the database field countryCode.
	 * In the database the field countryCode is of type varchar.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getCountryCode(){
		return $this->countryCode;
	}


	/**
	 * Set the value from the database field countryCode.
	 * In the database the field countryCode is of type varchar.
	 * The database field is NOT nullable.
	 * @param countryCode String with the value for the field to be set
	 */
	public function setCountryCode($countryCode){
		if(strlen($countryCode) > 20) throw new Exception("countryCode does not allow strings longer than 20 characters. The submitted string contains ".strlen($countryCode)." characters.");
		$this->countryCode = $countryCode;
	}


	/**
	 * Returns the value from the database field starRatingId.
	 * In the database the field starRatingId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getStarRatingId(){
		return $this->starRatingId;
	}


	/**
	 * Set the value from the database field starRatingId.
	 * In the database the field starRatingId is of type int.
	 * The database field is NOT nullable.
	 * @param starRatingId String with the value for the field to be set
	 */
	public function setStarRatingId($starRatingId){
		$this->starRatingId = $starRatingId;
	}


	/**
	 * Returns an object array containing all linked Hotelcharacteristics objects.
	 * A One to Many(1:n) relation exists between the Hotels and the Hotelcharacteristics.
	 * @return Hotelcharacteristics[] Array of Hotelcharacteristics instances
	 */
	public function getHotelcharacteristicss(){
	if($this->hotelcharacteristicsArray == null){
			$this->hotelcharacteristicsArray = array();
			$temphotelcharacteristics = new Hotelcharacteristics();
			$dataRowsTemp = $temphotelcharacteristics->dao->getData("`hotelId` = '$this->hotelId'");
			if(count($dataRowsTemp)  > 0)
			foreach($dataRowsTemp as $dataRow){
				$tempHotelcharacteristics = new Hotelcharacteristics();
				$tempHotelcharacteristics->init($dataRow);
				array_push($this->hotelcharacteristicsArray , $tempHotelcharacteristics);
			}
		}
		return $this->hotelcharacteristicsArray;
	}


	/**
	 * Returns an object array containing all linked Rooms objects.
	 * A One to Many(1:n) relation exists between the Hotels and the Rooms.
	 * @return Rooms[] Array of Rooms instances
	 */
	public function getRoomss(){
	if($this->roomsArray == null){
			$this->roomsArray = array();
			$temprooms = new Rooms();
			$dataRowsTemp = $temprooms->dao->getData("`hotelId` = '$this->hotelId'");
			if(count($dataRowsTemp)  > 0)
			foreach($dataRowsTemp as $dataRow){
				$tempRooms = new Rooms();
				$tempRooms->init($dataRow);
				array_push($this->roomsArray , $tempRooms);
			}
		}
		return $this->roomsArray;
	}


	/**
	 * Returns an object array containing all linked Roombookings objects.
	 * A One to Many(1:n) relation exists between the Hotels and the Roombookings.
	 * @return Roombookings[] Array of Roombookings instances
	 */
	public function getRoombookingss(){
	if($this->roombookingsArray == null){
			$this->roombookingsArray = array();
			$temproombookings = new Roombookings();
			$dataRowsTemp = $temproombookings->dao->getData("`hotelId` = '$this->hotelId'");
			if(count($dataRowsTemp)  > 0)
			foreach($dataRowsTemp as $dataRow){
				$tempRoombookings = new Roombookings();
				$tempRoombookings->init($dataRow);
				array_push($this->roombookingsArray , $tempRoombookings);
			}
		}
		return $this->roombookingsArray;
	}


	/**
	 * Set links to related Hotelcharacteristics instances. Existing links will be overwritten
	 * @param hotelcharacteristicsArray array of Hotelcharacteristics instances to be linked to this object instance
	 */
	public function setHotelcharacteristicss($hotelcharacteristicsArray){
		foreach($hotelcharacteristicsArray as $hotelcharacteristics)
			$hotelcharacteristics->hotelId = $this->hotelId;
		$this->hotelcharacteristicsArray = $hotelcharacteristicsArray;
	}


	/**
	 * Add a link to object of type Hotelcharacteristics
	 * @param hotelcharacteristics instance of Hotelcharacteristics to be linked to this object instance
	 */
	public function addHotelcharacteristics($hotelcharacteristics){
		$hotelcharacteristics->hotelId = $this->hotelId;
		if($this->hotelcharacteristicsArray == null) $this->hotelcharacteristicsArray = array();
		array_push($this->hotelcharacteristicsArray, $hotelcharacteristics);
	}


	/**
	 * Set links to related Rooms instances. Existing links will be overwritten
	 * @param roomsArray array of Rooms instances to be linked to this object instance
	 */
	public function setRoomss($roomsArray){
		foreach($roomsArray as $rooms)
			$rooms->hotelId = $this->hotelId;
		$this->roomsArray = $roomsArray;
	}


	/**
	 * Add a link to object of type Rooms
	 * @param rooms instance of Rooms to be linked to this object instance
	 */
	public function addRooms($rooms){
		$rooms->hotelId = $this->hotelId;
		if($this->roomsArray == null) $this->roomsArray = array();
		array_push($this->roomsArray, $rooms);
	}


	/**
	 * Set links to related Roombookings instances. Existing links will be overwritten
	 * @param roombookingsArray array of Roombookings instances to be linked to this object instance
	 */
	public function setRoombookingss($roombookingsArray){
		foreach($roombookingsArray as $roombookings)
			$roombookings->hotelId = $this->hotelId;
		$this->roombookingsArray = $roombookingsArray;
	}


	/**
	 * Add a link to object of type Roombookings
	 * @param roombookings instance of Roombookings to be linked to this object instance
	 */
	public function addRoombookings($roombookings){
		$roombookings->hotelId = $this->hotelId;
		if($this->roombookingsArray == null) $this->roombookingsArray = array();
		array_push($this->roombookingsArray, $roombookings);
	}


	/**
	 * Returns an instance of the linked Address object.
	 * A One to One(1:1) relation exists between the Address and the Hotels.
	 * @return Address the linked instance of Address
	 */
	public function getAddress(){
		if($this->address == null){
			$this->address = Address::loadUnique($this->addressId);
		}
		return $this->address;
	}


	/**
	 * Set a link to a related Address instance
	 * @param address instance of Address to be linked to this object instance
	 */
	public function setAddress($address){
		$address->addressId = $this->addressId;
		$this->address = $address;
	}


	/**
	 * Returns an instance of the linked Country object.
	 * A One to One(1:1) relation exists between the Country and the Hotels.
	 * @return Country the linked instance of Country
	 */
	public function getCountry(){
		if($this->country == null){
			$this->country = Country::loadUnique($this->countryCode);
		}
		return $this->country;
	}


	/**
	 * Set a link to a related Country instance
	 * @param country instance of Country to be linked to this object instance
	 */
	public function setCountry($country){
		$country->countryCode = $this->countryCode;
		$this->country = $country;
	}


	/**
	 * Returns an instance of the linked StarRatings object.
	 * A One to One(1:1) relation exists between the StarRatings and the Hotels.
	 * @return StarRatings the linked instance of StarRatings
	 */
	public function getStarRatings(){
		if($this->starRatings == null){
			$this->starRatings = StarRatings::loadUnique($this->starRatingId);
		}
		return $this->starRatings;
	}


	/**
	 * Set a link to a related StarRatings instance
	 * @param starRatings instance of StarRatings to be linked to this object instance
	 */
	public function setStarRatings($starRatings){
		$starRatings->starRatingId = $this->starRatingId;
		$this->starRatings = $starRatings;
	}
}
?>